<template>
	<view>
		<block v-if="!isLoading">
      <view class="p-t-30 m-l-20 m-r-20" v-if="!isEmpty">
        <block v-for="(item,index) in favoriteList" :key="item.id">
          <xy-course-row :item="item"/>
        </block>
      </view>
			<view v-else>
				<xy-empty text="您暂未收藏任何内容" />
			</view>
		</block>
	</view>
</template>


<script>
	import { mapState } from 'vuex';
	import xyEmpty from '@/components/xy-empty';
	import xyCourseRow from '@/components/xy-course/row';
	export default {
		components: {
			xyEmpty,
			xyCourseRow,
		},
		data() {
			return {

				isLoading:true,
				isEmpty: true,
				favoriteList: [],
				currentPage: 1,
				lastPage: 1,
				loadStatus: 'loadmore',
			}
		},
		computed: {
			...mapState(['common'])
		},
		async onLoad() {
			var that = this;

      this.loadData();
		},
		onPullDownRefresh() {
			this.currentPage = 1;
			this.favoriteList = [];
			this.loadData();
		},
		onReachBottom() {
			if(this.currentPage < this.lastPage) {
				this.currentPage += 1;
				this.loadData();
			}
		},
		methods: {
			async loadData(){
				this.$api.post({
					url: '/user_favorite/lists',
					loadingTip:'加载中...',
					data: {
						page: this.currentPage,
					},
					success: res => {
						uni.stopPullDownRefresh();
						this.isLoading = false;
						this.favoriteList = [...this.favoriteList, ...res.data];

						this.isEmpty = !this.favoriteList.length;
						this.currentPage = res.current_page; 
						this.lastPage = res.last_page;
						this.loadStatus = this.currentPage < res.last_page ? 'loadmore' : 'nomore';
					}
				});
			}
			
		}
	}
</script>

<style scoped lang="scss">
</style>
